package com.ruoyi.common.utils;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.LicensePlateOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.LicensePlateOCRResponse;

/**
 * 腾讯车牌识别
 */
public class LicensePlateOCRUtils {

    public static String distinguish(String akId, String akSecret, String ImageUrl) throws Exception{
        try{

            Credential cred = new Credential(akId, akSecret);

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);
            String params = "{\"ImageUrl\":\""+ImageUrl+"\"}";
            LicensePlateOCRRequest req = LicensePlateOCRRequest.fromJsonString(params, LicensePlateOCRRequest.class);

            LicensePlateOCRResponse resp = client.LicensePlateOCR(req);

            return LicensePlateOCRRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            throw new Exception(e.getMessage());
        }
    }


}
